import org.junit.Test;

import java.util.concurrent.locks.ReentrantLock;

public class 可重入锁 {

    ReentrantLock lock = new ReentrantLock();

    public void a() {
        lock.lock();
        //do some thing
        System.out.println("a");
        lock.unlock();
    }

    public void b() {
        lock.lock();
        //do some thing
        System.out.println("b");
        lock.unlock();
    }

    public void all() {
        lock.lock();
        //do some thing
        a();
        //do some thing
        b();
        //do some thing
        lock.unlock();
    }

    @Test
    public void test() {
        all();
    }

}
